package com.gragra.sampling.binary.tests;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import org.junit.Before;
import org.junit.Test;
import com.gragra.data.MixingCorpus;
import com.gragra.sampling.ThreadedUniformAccess;
import com.gragra.sampling.binary.BinaryInside;
import com.gragra.sampling.binary.BinaryStructure;
import com.gragra.sampling.binary.ToStringConverter;
import com.gragra.sampling.binary.UniformAssigner;
import com.gragra.sampling.sequentialStructure.WordAndTagHolder;
import com.gragra.sequentiaDataGenerator.BaseGenerator;
import com.gragra.sequentiaDataGenerator.EmptySegmentation;
/**
 * 
 * @author Christoph Teichmann
 * 18.09.2013
 */
public class TestBinaryInside
{
	/**
	 * 
	 */
	private UniformAssigner ua;
	/**
	 * 
	 */
	private ThreadedUniformAccess tua;
	/**
	 * 
	 */
	private BinaryStructure bsg;
	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception
	{
		StringReader sr = new StringReader("this|0 is|1 the|2 first|3 sentence|4");
		BufferedReader br = new BufferedReader(sr);
		BaseGenerator bg = new BaseGenerator(new EmptySegmentation());
		MixingCorpus<WordAndTagHolder> co = bg.createCorpus(br);
		bsg = new BinaryInside(co.getEntry(0), 10, new ToStringConverter(10),false);
		tua = new ThreadedUniformAccess(10);
		ua = new UniformAssigner(10);
		bsg.initialize(ua, tua);
	}
	@Test
	public void testResampleWithDepd() throws IOException
	{
		StringReader sr = new StringReader("this|0 is|1 the|2 first|3 sentence|4");
		BufferedReader br = new BufferedReader(sr);
		BaseGenerator bg = new BaseGenerator(new EmptySegmentation());
		MixingCorpus<WordAndTagHolder> co = bg.createCorpus(br);
		bsg = new BinaryInside(co.getEntry(0), 10, new ToStringConverter(10),true);
		tua = new ThreadedUniformAccess(10);
		ua = new UniformAssigner(10);
		bsg.initialize(ua, tua);
		for(int i=0;i<50000;++i)
		{
			for(int thread=0;thread<10;++thread)
			{bsg.resample(ua, 1.0, thread, tua);}
			bsg.addSample();
		}
	}
	@Test
	public void testResample()
	{
		for(int i=0;i<1000;++i)
		{
			for(int thread=0;thread<10;++thread)
			{bsg.resample(ua, 1.0, thread, tua);}
			bsg.addSample();
		}
	}
}